package com.example.book.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class NameStoreServlet
 */
@WebServlet("/nameStore")
public class NameStoreServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		response.setContentType("text/html");
		
		String name = request.getParameter("name");
		
		Cookie username = new Cookie("username", name);
		username.setMaxAge(10);
		response.addCookie(username);
		
		
		out.println("<html>");
		out.println("<body>");
		out.println("Welcome "+"<b>"+name+"</b>");
		out.println("</br>");
		out.println("<a href='http://localhost:8080/BBStore/catalog'>Back to catalog</a>");
		out.println("</body>");
		out.println("</html>");
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
